package com.lbj.googleplay.googleplay100.ui.fragment;

import android.view.View;

import com.lbj.googleplay.googleplay100.domain.CategoryInfo;
import com.lbj.googleplay.googleplay100.http.protocol.CategoryProtocol;
import com.lbj.googleplay.googleplay100.ui.adapter.MyBaseAdapter;
import com.lbj.googleplay.googleplay100.ui.holder.BaseHolder;
import com.lbj.googleplay.googleplay100.ui.holder.CategoryHolder;
import com.lbj.googleplay.googleplay100.ui.holder.TitleHolder;
import com.lbj.googleplay.googleplay100.ui.view.LoadingPage;
import com.lbj.googleplay.googleplay100.ui.view.MyListView;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import java.util.ArrayList;

/*
 * 分类
 * */
public class CategoryFragment extends BaseFragment {


    private ArrayList<CategoryInfo> data;

    @Override
    public View onCreateSuccessView() {

        MyListView listView = new MyListView(UIUtils.getContext());

        return null;
    }

    @Override
    public LoadingPage.ResultState onLoad() {
        CategoryProtocol protocol = new CategoryProtocol();
        data = protocol.getData(0);
        return check(data);
    }

    class CategoryAdapter extends MyBaseAdapter<CategoryInfo>{

        public CategoryAdapter(ArrayList<CategoryInfo> list) {
            super(list);
        }

        @Override
        public BaseHolder<CategoryInfo> getHolder(int position) {

            CategoryInfo info = data.get(position);

            if (info.isTitle){
                return  new TitleHolder();
            }else {
                return new CategoryHolder();
            }
        }

        @Override
        public ArrayList<CategoryInfo> onLoadMore() {
            return null;
        }

        @Override
        public int getViewTypeCount() {
            return super.getViewTypeCount()+1;//在原来基础上再加1种标题类型
        }

        @Override
        public int getInnerType(int position) {

            CategoryInfo info = data.get(position);
            //判断是标题类型还是普通分类类型
            if (info.isTitle){//返回标题类型
                return super.getInnerType(position)+1;

            }else {//返回普通类型
                return super.getInnerType(position);
            }
        }

        //重写此方法,不加载更多布局
        @Override
        public boolean hasMore() {
            return false;
        }
    }
}
